package com.wuwie.article.service.impl;


import com.wuwie.article.service.SubCommentService;
import com.mongodb.client.result.DeleteResult;
import com.wuwie.article.entity.SubComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SubCommentServiceImpl implements SubCommentService {

    @Autowired
    private MongoTemplate mongoTemplate;


    //全查询
    @Override
    public List<SubComment> select() {
        List<SubComment> students = mongoTemplate.findAll(SubComment.class);
        return students;
    }

    //删除
    @Override
    public long delcomment(String id) {
        Query query = new Query(Criteria.where("id").is(id));
        DeleteResult remove = mongoTemplate.remove(query, SubComment.class);
        long subComment = remove.getDeletedCount();
        return subComment;
    }

    //添加
    @Override
    public Integer Subaddcomment(SubComment subComment) {
        SubComment insert = mongoTemplate.insert(subComment);
        if (insert == null){
          return 1;
        }
        return 0;
    }
}
